import sys
import wx

from actions import *
from LMG.Utility.constants import *
from LMG.Tools.webservice import WEBSERVICE

def makeActionList():
    utility.actionGroup = {}
    
    actions = {}

    actions[ACTION_PAGE_SELECTION] = PageSelection()
    
    # Menus
    actions[ACTION_MENUFILE]    = FileMenu()
    actions[ACTION_MENUEDIT]    = EditMenu()
    actions[ACTION_MENUVIEW]    = ViewMenu()
    actions[ACTION_MENUTOOLS]   = ToolsMenu()
    actions[ACTION_MENUHELP]    = HelpMenu()
    
    
    # Base Actions
    actions[ACTION_ABOUT]               = About()
    actions[ACTION_PREFERENCES]         = Preferences()
    actions[ACTION_EXIT]                = Exit()
    actions[ACTION_MAKER]               = MakeTorrent()
    actions[ACTION_HOMEPAGE]            = HomePage()
    actions[ACTION_UPDATECHECK]         = UpdateCheck()
    actions[ACTION_ONIDLE]              = OnIdle()
    actions[ACTION_DIRSCANNER]          = DirectoryScanner()
    if WEBSERVICE:
        actions[ACTION_WEBSERVICE]          = WebService()
        actions[ACTION_WEBDIALOG]           = WebServicePreferences()
    actions[ACTION_CMDSCHEDULER]        = CommandScheduler()
    actions[ACTION_CMDSCHEDULERDIALOG]  = CommandSchedulerPreferences()
    actions[ACTION_TEMPLATESDIALOG]     = Templates()
    actions[ACTION_TEMPLATESMENU]       = TemplatesMenu()

    # Add Torrent
    actions[ACTION_MENU_ADDTORRENT]      = AddTorrentMenu()
    actions[ACTION_ADDTORRENTFROMFILE]   = AddTorrentFile()
    actions[ACTION_ADDTORRENTNONDEFAULT] = AddTorrentNonDefault()
    actions[ACTION_ADDTORRENTURL]        = AddTorrentURL()
    actions[ACTION_SCANTORRENTDIR]       = ScanTorrentDir()
    actions[ACTION_SCANURL]              = ScanURL()

    # Status Actions
    actions[ACTION_RESUME]      = Resume()
    actions[ACTION_PAUSE]       = Pause()
    actions[ACTION_STOP]        = Stop()
    actions[ACTION_QUEUE]       = Queue()
    actions[ACTION_SUPERSEED]   = SuperSeed()
    actions[ACTION_REMOVE]      = Remove()
    actions[ACTION_REMOVEFILE]  = RemoveFile()
    actions[ACTION_HASHCHECK]   = HashCheck()
    actions[ACTION_SCRAPE]      = Scrape()
    actions[ACTION_REANNOUNCE]  = UpdateTracker()
    actions[ACTION_ALLOCATE]    = FinishAllocation()

    actions[ACTION_STOPALL]     = StopAll()
    actions[ACTION_UNSTOPALL]   = UnStopAll()
    actions[ACTION_QUEUEACTIVE] = QueueActive()
    actions[ACTION_CLEARALL]    = ClearCompleted()

    # View Actions
    actions[ACTION_VIEWSEARCH]    = ViewSearch()
    actions[ACTION_VIEWLOG]       = ViewLog()
    actions[ACTION_VIEWRSS]       = ViewRss()
    actions[ACTION_VIEWTRANSFER]  = ViewTransfer()
    actions[ACTION_VIEWTOOLBAR]   = ViewToolbar()
    actions[ACTION_VIEWSTATUSBAR] = ViewStatusbar()
    actions[ACTION_CUSTOMIZE_TOOLBAR] = CustomizeToolbar()
    if wx.Platform == "__WXMSW__": actions[ACTION_THEME] = Theme()

    # Move Actions
    actions[ACTION_MOVEUP]      = MoveUp()
    actions[ACTION_MOVEDOWN]    = MoveDown()
    actions[ACTION_MOVEBOTTOM]  = MoveBottom()
    actions[ACTION_MOVETOP]     = MoveTop()
    
    # Other
    actions[ACTION_SEPARATOR]     = Separator()
    actions[ACTION_SAVETORRENT]   = SaveTorrent()
    actions[ACTION_OPENINCOMING]  = OpenIncoming()
    actions[ACTION_OPENDEST]      = OpenDest()
    actions[ACTION_OPENFILEDEST]  = OpenFileDest()
    actions[ACTION_CHANGEDEST]    = ChangeDest()
    actions[ACTION_TORRENTDETAILS]= TorrentInspector()
    actions[ACTION_SET_PRIORITY]  = ChangePriority() 
    
    imagelist = { "list": None, 
                  "imageToId": {}, 
                  "idToImage": {} }
    first = True
    for actionid in actions:
        action = actions[actionid]
    
        bitmap = action.bitmapsmall
        if bitmap is not None and action.shortdesc:            
            if first:
                width = bitmap.GetWidth()
                height = bitmap.GetHeight()
                imagelist["list"] = wx.ImageList(width, height)
                first = False
            
            imageindex = imagelist["list"].Add(bitmap)
            imagelist["imageToId"][imageindex] = actionid
            imagelist["idToImage"][actionid] = imageindex
            
    utility.actions = actions
    utility.imagelist = imagelist
